import {login} from "../../utils/asyncWx.js"
import { request } from "../../request/index"
import regeneratorRuntime from '../../lib/runtime/runtime';

Page({
  // 获取用户信息
  async handleGetUserInfo(e) {
    try {
      const {encryptedData, rawData, iv, signature} = e.detail;
      // 获取小程序登录成功后的code
      const {code} = await login();
      const loginParams = {encryptedData, rawData, iv, signature, code};
      // 发送请求 获取用户的token值
      // const {token} = await request({url:"/users/wxlogin", data:loginParams, methods:"post"});
      
      // 测试使用：因为没有企业账号，所以模拟返回了token
      let token = 'this is my token';
      // 把token存入到缓存中 同时跳转回上一个页面
      wx.setStorageSync('token', token);
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error);
    }
  }
})